<script type="text/javascript">
    function ajaxadd() {
        $.ajax({
            type: "post",
            data: $("#add").serialize(),
            //dataType:"json",
            url: "/student/save",
            success: function (result) {
                if (result !== "yes") {
                    alert("添加失败");
                } else {
                    alert("添加成功");
                    location.href = "/student/queryByName"
                }
            }

        })
    }

    $(function () {
        //隔行变色
        $("tr:even").css("background-color", "yellow");
        //a标签单击事件
        $("a").click(function () {
            //获取页码
            var no = $(this).attr("no");
            //获取form表单的参数
            var data = $("form").serialize();
            location.href = "/student/queryByName?" + data + "&pageNum=" + no;
        });
        //button按钮单击事件
        $("button[name='query']").click(function () {
            //获取当前button的id值
            var id = $(this).attr("no");
            location.href = "/student/querySyudentById?id=" + id;
        });
        //添加学生
        $("button[name='save']").click(function () {
            location.href = "/student/toSave"
        });
        //删除学生
        $("button[name='delete']").click(function () {
            //获取当前学生的id
            var id = $(this).attr("no");
            if (confirm("确定要删除该学生嘛?")) {
                $.ajax({
                    type: "post",
                    url: "/student/delete?id=" + id,
                    success: function (result) {
                        if (result == "yes") {
                            alert("删除成功");
                            location.href = "/student/queryByName"
                        } else {
                            alert("删除失败");
                        }
                    }

                })
            } else {
                return false;
            }
        })
    })
</script>